﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!--框架必需start-->
    <script src="scripts/jquery/jquery-1.10.2.min.js"></script>
    <link href="styles/font-awesome.min.css" rel="stylesheet" />
    <link href="scripts/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <script src="scripts/plugins/jquery-ui/jquery-ui.min.js"></script>
    <!--框架必需end-->
    <!--bootstrap组件start-->
    <link href="scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="scripts/bootstrap/css/bootstrap.extension.css" rel="stylesheet" />
    <script src="scripts/bootstrap/js/bootstrap.min.js"></script>
    <!--bootstrap组件end-->
    <script src="scripts/plugins/datepicker/WdatePicker.js"></script>
    <script src="scripts/layui/layui.js"></script>
    <link href="scripts/plugins/tree/tree.css" rel="stylesheet" />
    <link href="scripts/plugins/datetime/pikaday.css" rel="stylesheet" />
    <link href="scripts/plugins/wizard/wizard.css" rel="stylesheet" />
    <link href="styles/ui.css" rel="stylesheet" />
    <link href="scripts/plugins/simditor/css/simditor.css" rel="stylesheet" />
    <link href="scripts/plugins/cxColor/css/jquery.cxcolor.css" rel="stylesheet" />
    <link href="scripts/plugins/uploadify/uploadify.css" rel="stylesheet" />
    <link href="scripts/plugins/uploadify/uploadify.extension.css" rel="stylesheet" />
    <link href="scripts/plugins/flow-ui/flow.css" rel="stylesheet" />
    <link href="Styles/flow.css" rel="stylesheet" />
    <script src="scripts/plugins/tree/tree.js"></script>
    <script src="scripts/plugins/validator/validator.js"></script>
    <script src="scripts/plugins/wizard/wizard.js"></script>
    <script src="scripts/plugins/datepicker/datepicker.js"></script>
    <script src="scripts/utils/applayout.js"></script>
    <script src="scripts/utils/flowlayout.js"></script>
    <script src="scripts/utils/form.js"></script>
    <script src="scripts/utils/ui.js"></script>
    <script src="scripts/utils/applayout.js"></script>
    <script src="scripts/plugins/flow-ui/flow.js"></script>
    <script src="scripts/utils/form.js"></script>
    <script src="Scripts/utils/ui.js"></script>
    <script src="scripts/plugins/simditor/js/module.min.js"></script>
    <script src="scripts/plugins/simditor/js/uploader.min.js"></script>
    <script src="scripts/plugins/simditor/js/hotkeys.min.js"></script>
    <script src="scripts/plugins/simditor/js/simditor.min.js"></script>
    <script src="scripts/plugins/cxColor/js/jquery.cxcolor.js"></script>
    <script src="scripts/plugins/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">
        var layer;
        layui.use(['layer', 'form'], function () {
            layer = layui.layer;
        });
    </script>
    <script>
        var keyValue = 'R';
        var postData = {}; //提交数据
        var flowData = {};
        var frmData = {};
        var SchemeContentOld;
        var frmapp;
        var shcemeAuthorizeData = "";
        var AllAuthorizeCheckData = {};
        $(function () {
            initialPage();

            GetTree('User');
        })
        //初始化页面
        function initialPage() {
            //$('#step-1 .panel-body').height($(window).height() - 228);
            //$('#Description').height($(window).height() - 385);
            //$('#DesignateMemberlist').height($(window).height() - 141);
            //$('#Treebackground').height($(window).height() - 131);
            //$('#step-2 .tab-content').height($(window).height() - 167);
            //initFrmInfo();
            initFlowInfo();
            frmData.FrmContent = JSON.stringify("");
            //            FlowDesignPanel.loadData(frmData);
            var Flow_ApproveXML = parent.Flow_ApproveXML;
            //获取表单
            if (!!Flow_ApproveXML) {
                //                $.SetForm({
                //                    url: "GetFlowInfo.ashx/GetFlowInfos",
                //                    success: function (data) {
                //                        //                        $('#FormFrmTree').setNodeChecked(data.Frm.FrmId);
                //                        //                        frmData.FrmId = data.Frm.FrmId;
                //                        //                        setFrmInfo(data.Frm);
                //                        data = JSON.parse(data);
                //                        setFlowInfo(data.Flow);
                //                    }
                //                });
                Flow_ApproveXML = JSON.parse(Flow_ApproveXML);
                setFlowInfo(Flow_ApproveXML.Flow);
            }
        }

        /*=========流程设计（begin）==================================================================*/
        var FlowDesignPanel;
        var FlowDesignObject; //
        var LineId;
        var nodePramData = [];
        var Flow_Bill = "";//表单
        function initFlowInfo() {
            FlowDesignPanel = $('#FlowPanel').flowdesign({
                height: ($(window).height() - 27),
                widht: 1000,
                OpenNode: function (object) {
                    FlowDesignObject = object;
                    if (object.$nodeData[object.$focus].type == 'startround') {
                        return false;
                    }

                    layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['600px', '390px'], //宽高
                        maxmin: true, //开启最大化最小化按钮
                        title: '节点设置【' + object.$nodeData[object.$focus].name + '】',
                        content: 'FlowNodeForm.htm',
                        btn: ['保存', '关闭'],
                        yes: function (index, layero) {
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            iframeWin.AcceptClick();
                            layer.close(index);
                        },
                        cancel: function (index) {
                            layer.close(index);
                        }
                    });
                },
                OpenLine: function (id, object) {
                    FlowDesignObject = object;
                    LineId = id;
                    var _line = object.$lineData[id];
                    var _fromNode = object.$nodeData[_line.from];
                    if (_fromNode.type == "shuntnode")
                    {
                        dialogTop("前一个节点是分流节点无法设置流转条件", "error");
                        return false;
                    }
                    Flow_Bill=parent.selectValue;//表单
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['600px', '390px'], //宽高
                        maxmin: true, //开启最大化最小化按钮
                        title: '流转条件设置',
                        content: 'FlowLineForm.htm',
                        btn: ['保存', '关闭'],
                        yes: function (index, layero)
                        {
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            iframeWin.AcceptClick();
                            layer.close(index);
                        },
                        cancel: function (index) {
                            layer.close(index);
                        }
                    });

                }
            });
        }


        function setFlowInfo(data) {
            FlowDesignPanel.loadData(data);
        }
        function callBackNode(id, data, _nodePramData) {
            nodePramData = _nodePramData;
            FlowDesignPanel.SetNodeEx(id, data);
        }
        function callBackLine(id, data) {
            FlowDesignPanel.SetLineEx(id, data);
        }
        function bindingFlow() {
            var _content = FlowDesignPanel.exportDataEx();
            if (_content == -1) {
                return false;
            }
            flowData["SchemeContent"] = JSON.stringify({ "Frm": frmData, "Flow": _content });
            return true;
        }
        /*=========流程设计（end）====================================================================*/

        function GetTree(type) {

            //            $.ajax({
            //                url: "GetInfo.ashx",
            //                type: "Post",
            //                data: "", //请求Handler1.ashx下面的GetList方法
            //                success: function (data) {
            //                    AllAuthorizeCheckData[type] = $.arrayClone(data);
            //                }
            //            });
            //            $.SetForm({
            //                //url: "/UserManager/Get" + type + "CheckTreeJson",
            //                url: "GetInfo.ashx/GetUsers",
            //                success: function (data) {
            //                    AllAuthorizeCheckData[type] = $.arrayClone(data);

            //                }
            //            });
        }
        /*=========创建完成（begin）==================================================================*/

        //审批人列表
        var Flow_ApproveNames = "";
        var Flow_ApproveXML = "";
        var Flow_RUser = "";//审批人
        var Flow_RRole = "";//角色
        var Flow_RText = "";//提示语
        var Flow_RName = "";//步骤名称
        var Flow_HuiQian = "";//会签
        function finishbtn() {


            bindingFlow();


            var _content = FlowDesignPanel.exportDataEx();
            postData["EnabledMark"] = 1;
            // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            //            console.log(JSON.stringify(flowData));

            Flow_ApproveXML = JSON.stringify({ "Frm": frmData, "Flow": _content });


            var nodeBegin = ""; //开始节点
            var nodeEnd = ""; //结束节点

            for (var i = 0; i < _content.nodes.length; i++) {
                if (_content.nodes[i].name == "开始") {
                    nodeBegin = _content.nodes[i].id;
                }
                if (_content.nodes[i].name == "结束") {
                    nodeEnd = _content.nodes[i].id;
                }
            }


            var info = GetAppNames(_content, nodeBegin, nodeEnd);
            Flow_RUser = GetAppRUser(_content, nodeBegin, nodeEnd);
            Flow_RRole = GetAppRRole(_content, nodeBegin, nodeEnd);
            Flow_RText = GetAppRText(_content, nodeBegin, nodeEnd);
            Flow_RName = GetAppname(_content, nodeBegin, nodeEnd);
            //console.log('3344533');
            //console.log(Flow_RRole);
            //console.log(Flow_RName);
            //console.log('3333');
            for (var i = 0; i < info.length; i++) {
                if (Flow_ApproveNames.length > 0)
                    Flow_ApproveNames += ";";
                Flow_ApproveNames += info[i];
            }
            //if (Flow_ApproveNames.length > 0)
            //    Flow_ApproveNames += ":结束";

            while (Flow_ApproveXML.indexOf("\\\"") >= 0) {
                Flow_ApproveXML = Flow_ApproveXML.replace("\\\"", "");
            }
            parent.Flow_ApproveXML = Flow_ApproveXML;
            parent.Flow_ApproveNames = Flow_ApproveNames;
            parent.Flow_RUser = Flow_RUser;
            parent.Flow_RRole = Flow_RRole;
            parent.Flow_Rtext = Flow_RText;
            parent.Flow_RName = Flow_RName;
            //console.log(Flow_ApproveNames);
            //            $.SaveForm({
            //                url: "../../FlowManage/FlowDesign/SaveForm?keyValue=" + keyValue,
            //                param: { "InfoEntity": JSON.stringify(postData), "ContentEntity": JSON.stringify(flowData), "shcemeAuthorizeData": shcemeAuthorizeData },
            //                loading: "正在保存数据...",
            //                success: function () {
            //                    parent.layer.close(index);
            //                }
            //            })
        }
        function GetAppRUser(_content, nodeBegin, nodeEnd) {
            var info = new Array();
            var index = 0;
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeBegin) {
                    if (_content.lines[i].to != nodeEnd) {
                        var info1 = GetAppRUser(_content, _content.lines[i].to, nodeEnd);

                        if (info1.length > 0) {
                            for (var j = 0; j < info1.length; j++) {

                                info[index] = getRUser(_content, _content.lines[i], nodeEnd) + info1[j];
                                index++;
                            }
                        } else {
                            info[index] = getRUser(_content, _content.lines[i], nodeEnd);
                            index++;
                        }
                    }
                }
            }
            return info;
        }
        function GetAppRRole(_content, nodeBegin, nodeEnd) {
            var info = new Array();
            var index = 0;
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeBegin) {
                    if (_content.lines[i].to != nodeEnd) {
                        var info1 = GetAppRRole(_content, _content.lines[i].to, nodeEnd);

                        if (info1.length > 0) {
                            for (var j = 0; j < info1.length; j++) {

                                info[index] = getRRole(_content, _content.lines[i], nodeEnd) + info1[j];
                                index++;
                            }
                        } else {
                            info[index] = getRRole(_content, _content.lines[i], nodeEnd);
                            index++;
                        }
                    }
                }
            }
            return info;
        }
        function GetAppRText(_content, nodeBegin, nodeEnd) {
            var info = new Array();
            var index = 0;
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeBegin) {
                    if (_content.lines[i].to != nodeEnd) {
                        var info1 = GetAppRText(_content, _content.lines[i].to, nodeEnd);

                        if (info1.length > 0) {
                            for (var j = 0; j < info1.length; j++) {

                                info[index] = getRText(_content, _content.lines[i], nodeEnd) + info1[j];
                                index++;
                            }
                        } else {
                            info[index] = getRText(_content, _content.lines[i], nodeEnd);
                            index++;
                        }
                    }
                }
            }
            return info;
        }

        function GetAppname(_content, nodeBegin, nodeEnd) {
            var info = new Array();
            var index = 0;
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeBegin) {
                    if (_content.lines[i].to != nodeEnd) {
                        var info1 = GetAppname(_content, _content.lines[i].to, nodeEnd);

                        if (info1.length > 0) {
                            for (var j = 0; j < info1.length; j++) {
                                //console.log(1);
                                info[index] = getRname(_content, _content.lines[i], nodeEnd) + info1[j];
                                index++;
                            }
                        } else {
                            //console.log(2);
                            info[index] = getRname(_content, _content.lines[i], nodeEnd);
                            index++;
                        }
                    }
                }
            }
            return info;
        }
        function getRUser(_content, lines, nodeEnd) {
            var RUser = "";
            for (var k = 0; k < _content.nodes.length; k++) {
                if (_content.nodes[k].setInfo != undefined && _content.nodes[k].id != nodeEnd && _content.nodes[k].id == lines.to) {
                    RUser = _content.nodes[k].setInfo.RUser + "|";
                }
            }
            return RUser;
        }
        function getRRole(_content, lines, nodeEnd) {
            var RRole = "";
            for (var k = 0; k < _content.nodes.length; k++) {
                if (_content.nodes[k].setInfo != undefined && _content.nodes[k].id != nodeEnd && _content.nodes[k].id == lines.to) {
                    RRole = _content.nodes[k].setInfo.RRole + "|";
                }
            }
            return RRole;
        }
        function getRText(_content, lines, nodeEnd) {
            var RText = "";
            for (var k = 0; k < _content.nodes.length; k++) {
                if (_content.nodes[k].setInfo != undefined && _content.nodes[k].id != nodeEnd && _content.nodes[k].id == lines.to) {
                    RText = _content.nodes[k].setInfo.RText + "|";
                }
            }
            return RText;
        }
        function getRname(_content, lines, nodeEnd) {
            var Rname = "";
            for (var k = 0; k < _content.nodes.length; k++) {
                
                if (_content.nodes[k].setInfo != undefined && _content.nodes[k].id != nodeEnd && _content.nodes[k].id == lines.to) {
                    Rname = _content.nodes[k].name + "|";
                }
                //console.log(Rname);
            }
            return Rname;
        }

        function GetAppNames(_content, nodeBegin, nodeEnd) {
            var info = new Array();
            var index = 0;
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeBegin) {
                    if (_content.lines[i].to != nodeEnd) {
                        var info1 = GetAppNames(_content, _content.lines[i].to, nodeEnd);

                        if (info1.length > 0) {
                            for (var j = 0; j < info1.length; j++) {

                                info[index] = getApproveName(_content, _content.lines[i], nodeEnd) + info1[j];
                                index++;
                            }
                        } else {
                            info[index] = getApproveName(_content, _content.lines[i], nodeEnd);
                            index++;
                        }
                    }
                }
            }
            return info;
        }
        function getApproveName(_content, lines, nodeEnd) {
            var ApproveName = "";
            if (lines.setInfo != undefined)
            {
                if (lines.setInfo.selAndOr != "0")
                {
                    ApproveName += lines.setInfo.selField + "," + lines.setInfo.selEqual + "," + lines.setInfo.txtValue;

                    if (lines.setInfo.selAndOr == "1")
                        ApproveName += "&";
                    else
                        ApproveName += "^";
                    ApproveName += lines.setInfo.selField1 + "," + lines.setInfo.selEqual1 + "," + lines.setInfo.txtValue1;
                }
                else
                {
                    ApproveName += lines.setInfo.selField + "," +lines.setInfo.selEqual + "," + lines.setInfo.txtValue;
                }
                ApproveName += ":";
            }
           
            for (var k = 0; k < _content.nodes.length; k++) {
               
               
                if (_content.nodes[k].setInfo != undefined && _content.nodes[k].id != nodeEnd && _content.nodes[k].id == lines.to)
                {
                    var vNodeName = _content.nodes[k].setInfo.NodeName + "@";
                    console.log(_content.nodes[k].setInfo);
                    if (_content.nodes[k].setInfo.isSetAppp != undefined && _content.nodes[k].setInfo.isSetAppp != "")
                    {
                        //alert(_content.nodes[k].setInfo.isSetAppp);
                        ApproveName += vNodeName + "【" + _content.nodes[k].setInfo.isSetAppp + "】#0,1|";
                    }
                    else
                    {
                        if (_content.nodes[k].setInfo.NodeDesignate == 'NodeDesignateType2') {
                            if (_content.nodes[k].setInfo.NodeDesignateData.user.length > 0 || _content.nodes[k].setInfo.NodeDesignateData.role.length > 0) {
                                var userLength = _content.nodes[k].setInfo.NodeDesignateData.user.length;
                                var nodname = '';
                                for (var h = 0; h < userLength; h++) {
                                    nodname += "U_" + _content.nodes[k].setInfo.NodeDesignateData.user[h] + ",";
                                    //ApproveName += vNodeName +"U_" + _content.nodes[k].setInfo.NodeDesignateData.user[h] + ",";
                                }
                                
                                for (var h = 0; h < _content.nodes[k].setInfo.NodeDesignateData.role.length; h++) {
                                    nodname += "R_" + _content.nodes[k].setInfo.NodeDesignateData.role[h] + ",";
                                    //ApproveName += vNodeName +"R_" + _content.nodes[k].setInfo.NodeDesignateData.role[h] + ",";
                                }
                                ApproveName += vNodeName + nodname;
                                //if (_content.nodes[k].setInfo.isHuiQian)
                                //    ApproveName += "#" + userLength + ",1|";
                                //else
                                ApproveName += "#" + _content.nodes[k].setInfo.NodeConfluenceType + "," + _content.nodes[k].setInfo.NodeConfluenceRate + "|";
                                
                            } else {
                                ApproveName += vNodeName +"【任意审批】#0,1|";
                            }
                        } else {
                            ApproveName += vNodeName + "【" + _content.nodes[k].setInfo.NodeDesignateType + "】#0," + _content.nodes[k].setInfo.NodeConfluenceRate + "|";
                        }
                    }
                }
            }
      
            return ApproveName;

        }

        function ForInfo(_content, nodeName, nodeEnd) {
            var Flow_ApproveName = "";
            var linesBegin = "";
            for (var i = 0; i < _content.lines.length; i++) {
                if (_content.lines[i].from == nodeName) {
                    if (linesBegin.length > 0)
                        linesBegin += ",";
                    linesBegin += i;
                }
                if (_content.lines[i].from == nodeEnd) {
                    i = _content.lines.length;
                }
            }
            if (linesBegin != "") {
                for (var i = 0; i < linesBegin.split(',').length; i++) {
                    Flow_ApproveName += _content.lines[linesBegin.split(',')[i]].id + "|";
                    var nf = ForInfo(_content, _content.lines[linesBegin.split(',')[i]].to, nodeEnd);
                    if (nf != "")
                        Flow_ApproveName += nf + "|";
                }
            }
            return Flow_ApproveName;
        }
        /*=========创建完成（end）====================================================================*/


        function callBackNode(id, data, _nodePramData) {
            nodePramData = _nodePramData;
            FlowDesignPanel.SetNodeEx(id, data);
        }
    </script>
    <style>
        .editviewtitle {
            position: fixed !important;
            top: 117px;
            right: 11px;
            width: 50px;
            z-index: 1000;
        }

        .standtab-pane {
            width: 224px;
            border-right: 1px solid #ccc;
            float: left;
        }

        .SchemeAuthorizePanel {
            width: 828px;
            float: left;
            display: none;
        }

        .card-box.active {
            background: url(/Images/item_close.png) right top no-repeat !important;
        }
    </style>
</head>
<body>
    <div class="widget-body">
        <div class="step-content wizard-step-content" id="wizard-steps" style="background-color: red;">
            <div id="FlowPanel" style="margin: 0px;"></div>
        </div>
        <div class="form-button" id="wizard-actions" style="display:none;">
            <a id="btn_last" class="btn btn-default btn-prev">上一步</a>
            <a id="btn_next" class="btn btn-default btn-next">下一步</a>
            <a id="btn_finish" class="btn btn-success" onclick="finishbtn();">保存</a>
        </div>
    </div>
</body>
</html>
